class Solution {
public:
	string multiply(string num1, string num2) {
		if (num1[0] == '0' || num2[0] == '0')
			return "0";
		size_t size = num1.size() + num2.size();
		vector<int> v;
		v.resize(size);
		string::reverse_iterator end2 = num2.rbegin();
		vector<int>::reverse_iterator endV = v.rbegin();
		while (end2 != num2.rend())
		{
			string::reverse_iterator end1 = num1.rbegin();
			vector<int>::reverse_iterator v_it = endV;
			int b = *end2 - '0';
			while (end1 != num1.rend())
			{
				int a = *end1 - '0';
				int mul = a * b;
				*v_it += mul;
				v_it++;
				end1++;
			}
			endV++;
			end2++;
		}
		endV = v.rbegin();
		string ret;
		int next = 0;
		while (endV != v.rend())
		{
			*endV += next;
			next = 0;
			if (*endV >= 10)
			{
				next = *endV / 10;
				*endV %= 10;
			}
			ret += *endV + '0';
			endV++;
		}
		if (ret.back() == '0')
			ret.pop_back();
		reverse(ret.begin(), ret.end());
		return ret;
	}
};